<?php
    class HomeController extends Controller
    {    
        public function actionError()
        {        
            $this->layout = false;
            $error = Yii::app()->errorHandler->error; 
            if($_SERVER["HTTP_HOST"]=="localhost"){
                var_dump($error);die;
            }           
            $this->render("error"
            , array(
            "error"=>$error
            )            
            );
        }

        public function actionIndex(){
            
            $this->linkCanoncical = Url::createUrl('home/index');
            $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";

            $currentPage = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
            $currentPage = $currentPage==0 ? 1 : $currentPage;
            $numberRecordPerPage = 5;
            $event = Event::getEventActive($currentPage,$numberRecordPerPage);
            $data_gameonl = Game::getGameOnline($currentPage,$numberRecordPerPage);
            $data_gameoff = Game::getGameOffline($currentPage,$numberRecordPerPage);
            $data_app     = App::getOtherApp($currentPage,$numberRecordPerPage);
            $data_clip = Clip::getVideoHot($currentPage,$numberRecordPerPage);
            $latest_clip = Clip::getLatestVideo();
            $this->render("index",array("data_gameonl"=>$data_gameonl,"data_gameoff"=>$data_gameoff,"data_app"=>$data_app,"event"=>$event,"data_clip"=>$data_clip,"latest_clip"=>$latest_clip));
        }
        public function actionGameOffline(){
            $this->linkCanoncical = Url::createUrl('home/gameOffline');
            $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";
            $this->breadcrumbs[] = array('name'=>'Game Offline','link'=>'#','class'=>'active'); 

            $currentPage = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
            $currentPage = $currentPage==0 ? 1 : $currentPage;
            $numberRecordPerPage = 5;
            $totalGameOffline = Game::getTotalGameOffline();
            $numberPage = ceil($totalGameOffline/$numberRecordPerPage);

            $url = Url::createUrl("home/gameOffline");
            $url1 = rtrim($url,"/");
            $url.='/';
            $paging = Paging::show_paging_wap_user($numberPage,$currentPage,$url,$url1);
            $data_gameoff = Game::getGameOffline($currentPage,$numberRecordPerPage);
            $this->render("game_off",array("data_gameoff"=>$data_gameoff,"paging"=>$paging));
        }
        public function actionGameOnline(){
            $this->linkCanoncical = Url::createUrl('home/gameOnline');
            $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";
            $this->breadcrumbs[] = array('name'=>'Game Online','link'=>'#','class'=>'active'); 

            $currentPage = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
            $currentPage = $currentPage==0 ? 1 : $currentPage;
            $numberRecordPerPage = 5; 

            $totalGameOnline = Game::getTotalGameOnline();
            $numberPage = ceil($totalGameOnline/$numberRecordPerPage);

            $data_gameonl = Game::getGameOnline($currentPage,$numberRecordPerPage);
            $url = Url::createUrl("home/gameOnline");
            $url1 = rtrim($url,"/");
            $url.='/';
            $paging = Paging::show_paging_wap_user($numberPage,$currentPage,$url,$url1);
            $this->render("game_onl",array("data_gameonl"=>$data_gameonl,'paging'=>$paging));
        }
        public function actionApp(){
            $this->linkCanoncical = Url::createUrl('home/app');
            $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";
            $this->breadcrumbs[] = array('name'=>'Ứng dụng','link'=>'#','class'=>'active'); 

            $currentPage = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
            $currentPage = $currentPage==0 ? 1 : $currentPage;
            $numberRecordPerPage = 5;

            $totalGameOnline = App::getTotalApp();
            $numberPage = ceil($totalGameOnline/$numberRecordPerPage);

            $data_app = App::getOtherApp($currentPage,$numberRecordPerPage);
            $url = Url::createUrl("home/app");
            $url1 = rtrim($url,"/");
            $url.='/';
            $paging = Paging::show_paging_wap_user($numberPage,$currentPage,$url,$url1);
            $this->render("app",array("paging"=>$paging,"data_app"=>$data_app));
        }
        public function actionDetail(){
            $this->linkCanoncical = Url::createUrl('home/index');
             $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";
            $this->breadcrumbs[] = array('name'=>'Ứng dụng','link'=>'#','class'=>'active'); 
            $type = isset($_GET['type']) ? intval($_GET['type']) : 0;
            $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
            if($type == 1){
                $data_detail = Game::getInfoGame($id);
                $data_random = Game::getRandomGame($data_detail['isOnline']);
            }
            if($type == 2){
                $data_detail = App::getInfoApp($id)  ;
                $data_random = App::getRandomApp()  ;
            }
            if($type == 3){
                $data_detail = Event::getInfoEvent($id);
                $data_random = Event::getRandomEvent();
            }
            if(empty($data_detail)){
                $this->redirect(Url::createUrl("home/noData"));
            }
            $this->breadcrumbs[] = array('name'=>$data_detail['title'],'link'=>'#','class'=>'active');
            $this->render("detail",array("data_detail"=>$data_detail,"data_random"=>$data_random,"type"=>$type));
        }
         public function actionEvent(){
            $this->linkCanoncical = Url::createUrl('home/event');
             $this->metaTitle = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaKeywords = "Tai game online, tai game offline, tai ung dung hay, tai clip hot";
            $this->metaDescription = "Wap Site Tai Game Mobile, Tai Ung dung , Tai Clip Hot nhat Viet Nam";
            $this->breadcrumbs[] = array('name'=>'Sự kiện','link'=>'#','class'=>'active'); 

            $currentPage = isset($_GET["page"]) ? intval($_GET["page"]) : 1;
            $currentPage = $currentPage==0 ? 1 : $currentPage;
            $numberRecordPerPage = 5;

            $totalEvent = Event::getTotalEvent();
            $numberPage = ceil($totalEvent/$numberRecordPerPage);
            
            $data_event = Event::getEventActive($currentPage,$numberRecordPerPage);
            $url = Url::createUrl("home/event");
            $url1 = rtrim($url,"/");
            $url.='/';
            $paging = Paging::show_paging_wap_user($numberPage,$currentPage,$url,$url1);
            $this->render("event",array("paging"=>$paging,"data_event"=>$data_event));
        }
        
        public function actionNoData(){
            $this->render("error"); 
        }

    }
?>
